<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of add_var_FVCOM_river</title>
  <meta name="keywords" content="add_var_FVCOM_river">
  <meta name="description" content="add time dependent scalar variable to a Riverfile">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">fvcom_prepro</a> &gt; add_var_FVCOM_river.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for fvcom_prepro&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>add_var_FVCOM_river
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>add time dependent scalar variable to a Riverfile</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function add_var_FVCOM_river(RiverFile,VarName,VarLongName,VarUnits,VarData) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> add time dependent scalar variable to a Riverfile 

 function add_var_FVCOM_river(RiverFile,VarName,VarLongName,VarUnits,VarData)

 DESCRIPTION:
    Write an additional scalar variable (e.g. sediment, DO) to a NetCDF
    River file.  Note that the concentration of the scalar variable
    is set the same at all river points in the file so it is assumed 
    that even if the file contains multiple nodes, they all refer to the same
    river.

 INPUT
    RiverFile:   FVCOM 3.x NetCDF river forcing file
    VarName:     Variable name (will be the name of the array in the NetCDF file)
    VarLongName: Variable attribute &quot;long_name&quot;
    VarUnits:    Variable attribute &quot;units&quot;
    VarData:     1-D Time series of variable data of exact same dimensions as 
                 the river flux 
   
 OUTPUT:
    Modified FVCOM RiverFile

 EXAMPLE USAGE
    add_var_FVCOM_river('tst_riv.nc','medium_sand','medium sand','kg-m^-3',sand_ts)  

 Author(s):  
    Geoff Cowles (University of Massachusetts Dartmouth)

 Revision history
   
==============================================================================</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="example_FVCOM_river.html" class="code" title="function example_FVCOM_river()">example_FVCOM_river</a>	example file for dumping an FVCOM river file and adding sediment concentration</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function add_var_FVCOM_river(RiverFile,VarName,VarLongName,VarUnits,VarData)</a>
0002 <span class="comment">% add time dependent scalar variable to a Riverfile</span>
0003 <span class="comment">%</span>
0004 <span class="comment">% function add_var_FVCOM_river(RiverFile,VarName,VarLongName,VarUnits,VarData)</span>
0005 <span class="comment">%</span>
0006 <span class="comment">% DESCRIPTION:</span>
0007 <span class="comment">%    Write an additional scalar variable (e.g. sediment, DO) to a NetCDF</span>
0008 <span class="comment">%    River file.  Note that the concentration of the scalar variable</span>
0009 <span class="comment">%    is set the same at all river points in the file so it is assumed</span>
0010 <span class="comment">%    that even if the file contains multiple nodes, they all refer to the same</span>
0011 <span class="comment">%    river.</span>
0012 <span class="comment">%</span>
0013 <span class="comment">% INPUT</span>
0014 <span class="comment">%    RiverFile:   FVCOM 3.x NetCDF river forcing file</span>
0015 <span class="comment">%    VarName:     Variable name (will be the name of the array in the NetCDF file)</span>
0016 <span class="comment">%    VarLongName: Variable attribute &quot;long_name&quot;</span>
0017 <span class="comment">%    VarUnits:    Variable attribute &quot;units&quot;</span>
0018 <span class="comment">%    VarData:     1-D Time series of variable data of exact same dimensions as</span>
0019 <span class="comment">%                 the river flux</span>
0020 <span class="comment">%</span>
0021 <span class="comment">% OUTPUT:</span>
0022 <span class="comment">%    Modified FVCOM RiverFile</span>
0023 <span class="comment">%</span>
0024 <span class="comment">% EXAMPLE USAGE</span>
0025 <span class="comment">%    add_var_FVCOM_river('tst_riv.nc','medium_sand','medium sand','kg-m^-3',sand_ts)</span>
0026 <span class="comment">%</span>
0027 <span class="comment">% Author(s):</span>
0028 <span class="comment">%    Geoff Cowles (University of Massachusetts Dartmouth)</span>
0029 <span class="comment">%</span>
0030 <span class="comment">% Revision history</span>
0031 <span class="comment">%</span>
0032 <span class="comment">%==============================================================================</span>
0033 
0034 warning off
0035 
0036 subname = <span class="string">'add_var_FVCOM_river'</span>;
0037 <span class="keyword">global</span> ftbverbose;
0038 <span class="keyword">if</span>(ftbverbose);
0039   fprintf(<span class="string">'\n'</span>)
0040   fprintf([<span class="string">'begin : '</span> subname <span class="string">'\n'</span>])
0041 <span class="keyword">end</span>;
0042 
0043 <span class="keyword">if</span>(ftbverbose);fprintf(<span class="string">'adding variable %s to file %s\n'</span>,VarName,RiverFile); <span class="keyword">end</span>;
0044 
0045 <span class="comment">%------------------------------------------------------------------------------</span>
0046 <span class="comment">% Open River Netcdf and read dimensions</span>
0047 <span class="comment">%------------------------------------------------------------------------------</span>
0048 <span class="keyword">if</span>(~exist(RiverFile))
0049     error([<span class="string">'file: '</span> RiverFile <span class="string">' does not exist'</span>]);
0050 <span class="keyword">end</span>;
0051 
0052 nc = netcdf(RiverFile, <span class="string">'w'</span>);  
0053  
0054 <span class="comment">% read dimensions</span>
0055 flux = nc{<span class="string">'river_flux'</span>}(:,:);
0056 [nTimes,nRivnodes]= size(flux);
0057 
0058 <span class="comment">% make sure time dimension matches FVCOM river dims</span>
0059 tempTimes = prod(size(VarData));
0060 <span class="keyword">if</span>(nTimes ~= tempTimes)
0061     fprintf(<span class="string">'# of time frames in file %s is %d\n'</span>,RiverFile,tempTimes)
0062     fprintf(<span class="string">'# of time frames in VarData is %d\n'</span>,nTimes)
0063     error(<span class="string">'you have chosen the wrong vocation'</span>)
0064 <span class="keyword">end</span>;
0065 
0066 
0067 <span class="comment">%------------------------------------------------------------------------------</span>
0068 <span class="comment">% Write variable definition and data and close file</span>
0069 <span class="comment">%------------------------------------------------------------------------------</span>
0070 
0071 <span class="comment">% set field</span>
0072 river_field = zeros(nTimes,nRivnodes);
0073 <span class="keyword">for</span> i=1:nTimes
0074     river_field(i,1:nRivnodes) = VarData(i);
0075 <span class="keyword">end</span>;
0076 
0077 
0078 
0079 <span class="comment">%--------------------------------------------------------------</span>
0080 <span class="comment">% dump to netcdf file</span>
0081 <span class="comment">%--------------------------------------------------------------</span>
0082 
0083 <span class="comment">% open boundary forcing</span>
0084 nc = netcdf(RiverFile, <span class="string">'w'</span>);    
0085 nc{VarName} = ncfloat(<span class="string">'time'</span>,<span class="string">'rivers'</span>);
0086 nc{VarName}.long_name = VarLongName; 
0087 nc{VarName}.units     = VarUnits;   
0088 
0089 <span class="comment">% dump dynamic data</span>
0090 <span class="keyword">for</span> i=1:nTimes
0091   nc{VarName}(i,1:nRivnodes) = river_field(i,1:nRivnodes); 
0092 <span class="keyword">end</span>;
0093 
0094 nc = close(nc);    
0095 
0096 
0097 <span class="keyword">if</span>(ftbverbose);
0098   fprintf([<span class="string">'end   : '</span> subname <span class="string">'\n'</span>])
0099 <span class="keyword">end</span>;
0100</pre></div>
<hr><address>Generated on Wed 02-Nov-2011 21:58:00 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>